<template>
	<view>
		<view class="list">
			<view class="item">
				<view class="left">
					当前日期:
				</view>
				<view class="right">
					{{curtoday}}
				</view>
			</view>
			<view class="item">
				<view class="left">
					上班时间:
				</view>
				<view class="right">
				{{sbsj}}
				</view>
			</view>
			<view class="item">
				<view class="left">
					下班时间:
				</view>
				<view class="right">
					{{xbsj}}
				</view>
			</view>
			<view class="item">
				<view class="left">
					门店:
				</view>
				<view class="right">
					{{mdname}}
				</view>
			</view>
		</view>
		<view class="daka">
			<view class="centerinlnie" @click="toKaoQin()">
				<text class="wenzi">打卡</text>
			</view>
		</view>
		<u-tabbar :value="value1" :fixed="true" :placeholder="false" :safeAreaInsetBottom="false">
			<u-tabbar-item text="打卡" icon="map" @click="click1"></u-tabbar-item>
			<u-tabbar-item text="统计" icon="photo" @click="click1"></u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value1: 0,
				yg_id: '',
				curYear: '', //年
				curMonth: '', //月
				curDay: '' ,//日
				curtoday:'',//当前日期
				StaffSchedulingData:[],//排班数据
				today_sbrq:{},
				dqjs:'',
				mendian_id:'',
				sbsj:'',
				xbsj:'',
				pbid:'',//排班id
				mdname:''
				
				

			}
		},
		onLoad(options) {
			let yg_id = options.yg_id;
			this.yg_id = yg_id;
			
		},
		onShow() {
			this.value1 = 0;
			var that = this;
			uni.getStorage({
				key: 'user_key',
				complete: function(res) {
					// console.log(666,res)
					that.yg_id=res.data.id
					that.dqjs=res.data.role
					that.mendian_id=res.data.mendian
					that.getExecutor(res.data.mendian)
				}
			})
		},
		onReady() {
			var date = new Date();
			var seperator1 = "-";
			var year = date.getFullYear();
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			let today = year + seperator1 + month + seperator1 + strDate;
			this.curtoday = today;
				console.log(this.curtoday)
			if (this.curtoday) {
				this.curYear =this.curtoday.substring(0, 4);
				this.curMonth = this.curtoday.substring(6, 7);
				this.curDay = this.curtoday.substring(8, 10);
				// console.log(this.curYear + "," + this.curMonth)
				

			}
			// this.markDays.push(today);
			this.getStaffScheduling(this.yg_id, this.curYear, this.curMonth)
		},
		methods: {
			//打卡
			toKaoQin(){
				console.log(this.mendian_id,this.pbid)
				uni.request({
					url: getApp().globalData.url + '/client/AddKaoqin',
					method: 'POST',
					data: {
						id:this.mendian_id,
						bancid:this.pbid,
						longitude:22.790255,
						latitude:108.27619
					},
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					success: function(res) {
						// console.log(888, res)
						if (res.data.code == 200) {
						uni.showToast({
							icon: 'none',
							position: 'center',
							title: res.data.msg
						});
						} else if (res.data.code == 400) {
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: "查询排班数据为空"
							});
						} else {
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: "请求异常"
							});
						}
					}
				})
			},
			//获取门店信息
			getExecutor(mendian_id) {
				let _that = this;
				wx.request({
					url: getApp().globalData.url + '/client/GetMendxq',
					method: 'GET',
					data: {
						id: mendian_id
					},
					header: {
						"Content-Type": "application/json"
					},
					success: function(res) {
						if (res.data.code == 200 && res.data.msg == '查询成功') {
							// console.log(999,res)
							_that.mdname=res.data.data.mdname
							
						} else {
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: "请求出现异常！"
							});
						}
					}
				})
			},
			//获取员工排班结果
			getStaffScheduling(a, b, c) {
				let _that = this;
				// console.log("员工id:" + a)
				// console.log("年:" + b)
				// console.log("月:" + c)
				uni.request({
					url: getApp().globalData.url + '/client/GetBaiblist?id=' + a + '&year=' + b + '&month=' + c,
					method: 'GET',
					data: {},
					header: {
						"Content-Type": "application/json"
					},
					success: function(res) {
						// console.log(888, res)
						if (res.data.code == 200 && res.data.msg == '查询成功') {
							_that.StaffSchedulingData = res.data.data;
							for (let i = 0; i < _that.StaffSchedulingData.length; i++){
								let sbri_day=_that.StaffSchedulingData[i].sbriq;
								sbri_day=sbri_day.substring(8,10);
								// console.log(444,sbri_day)
								if(sbri_day==_that.curDay){
									_that.today_sbrq=_that.StaffSchedulingData[i];
									_that.pbid=_that.StaffSchedulingData[i].id;
									var bc=_that.StaffSchedulingData[i].bcid;
									if(bc){
										_that.sbsj=bc.kssj;
										_that.xbsj=bc.jssj;
									}
								}
								
							}
						} else if (res.data.code == 400) {
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: "查询排班数据为空"
							});
						} else {
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: "请求异常"
							});
						}
					}
				})
			},
			click1(e) {
				console.log('click1', e);
				this.value1 = e
				if (e == 0) {
					uni.navigateTo({
						url: '/pages/punchTheClock/punchTheClock'
					})
				}
				if (e == 1) {
					uni.navigateTo({
						url: '/pages/yuangkqcg/yuangkqcg?yg_id=' + this.yg_id
					})
				}
			},

		}
	}
</script>

<style>
	page {
		background: #F0F0F0;
		height: auto;
		min-height: 100%;
	}
</style>
<style lang="scss" scoped>
	.list {
		padding-top: 30rpx;

		.item {
			display: flex;
			height: 80rpx;
			margin: auto 30rpx 20rpx 30rpx;
			border: 1rpx solid #D3D3D3;
			background-color: #fff;
			line-height: 80rpx;
			border-radius: 16rpx;

			.left {
				height: 80rpx;
				width: 20%;
				font-weight: bold;
				margin-left: 10rpx;
			}

			.right {
				text-align: center;
				height: 80rpx;
				width: 80%;
				color: #989EB8;
			}
		}
	}

	.daka {
		height: 200rpx;
		text-align: center;
		margin-top: 150rpx;

		.centerinlnie {
			height: 200rpx;
			width: 200rpx;
			background-color: #007AFF;
			color: #FFFFFF;
			font-weight: bold;
			text-align: center;
			border-radius: 50%;
			display: inline-block;

			.wenzi {
				line-height: 200rpx;
			}
		}
	}
</style>
